5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * @author Mike Lively <m@digitalsandwich.com>
40 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 3.3.0
47 require_once 'PHPUnit/Framework/TestCase.php';
48 require_once 'PHPUnit/Extensions/Database/DataSet/ReplacementTable.php';
49 require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php';
50 require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php';
51 require_once 'PHPUnit/Extensions/Database/TestCase.php';
56 * @author Mike Lively <m@digitalsandwich.com>
57 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
58 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
60 * @link http://www.phpunit.de/
61 * @since File available since Release 3.3.0
63 class Extensions_Database_DataSet_ReplacementTableTest extends PHPUnit_Framework_TestCase
66 * @var PHPUnit_Extensions_Database_DataSet_DefaultTable
68 protected $startingTable;
70 public function setUp()
72 $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
73 'table1', array('table1_id', 'column1', 'column2', 'column3', 'column4')
76 $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
80 'column1' => 'My name is %%%name%%%',
83 'column4' => 'yghkf;a hahfg8ja h;'
87 'column1' => 'hk;afg',
90 'column4' => '24rwehhads'
94 'column1' => 'ha;gyt',
96 'column3' => '[NULL] not really',
100 $this->startingTable = $table;
103 public function testNoReplacement()
105 PHPUnit_Extensions_Database_TestCase::assertTablesEqual(
106 $this->startingTable,
107 new PHPUnit_Extensions_Database_DataSet_ReplacementTable($this->startingTable)
111 public function testFullReplacement()
113 $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
114 'table1', array('table1_id', 'column1', 'column2', 'column3', 'column4')
117 $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
119 $table->addRow(array(
121 'column1' => 'My name is %%%name%%%',
124 'column4' => 'yghkf;a hahfg8ja h;'
126 $table->addRow(array(
128 'column1' => 'hk;afg',
131 'column4' => '24rwehhads'
133 $table->addRow(array(
135 'column1' => 'ha;gyt',
137 'column3' => '[NULL] not really',
141 $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementTable($this->startingTable);
142 $actual->addFullReplacement('[NULL]', NULL);
144 PHPUnit_Extensions_Database_TestCase::assertTablesEqual($table, $actual);
147 public function testSubStrReplacement()
149 $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
150 'table1', array('table1_id', 'column1', 'column2', 'column3', 'column4')
153 $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
155 $table->addRow(array(
157 'column1' => 'My name is Mike Lively',
160 'column4' => 'yghkf;a hahfg8ja h;'
162 $table->addRow(array(
164 'column1' => 'hk;afg',
167 'column4' => '24rwehhads'
169 $table->addRow(array(
171 'column1' => 'ha;gyt',
173 'column3' => '[NULL] not really',
174 'column4' => '[NULL]'
177 $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementTable($this->startingTable);
178 $actual->addSubStrReplacement('%%%name%%%', 'Mike Lively');
180 PHPUnit_Extensions_Database_TestCase::assertTablesEqual($table, $actual);
183 public function testConstructorReplacements()
185 $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
186 'table1', array('table1_id', 'column1', 'column2', 'column3', 'column4')
189 $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
191 $table->addRow(array(
193 'column1' => 'My name is Mike Lively',
196 'column4' => 'yghkf;a hahfg8ja h;'
198 $table->addRow(array(
200 'column1' => 'hk;afg',
203 'column4' => '24rwehhads'
205 $table->addRow(array(
207 'column1' => 'ha;gyt',
209 'column3' => '[NULL] not really',
213 $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementTable(
214 $this->startingTable,
215 array('[NULL]' => NULL),
216 array('%%%name%%%' => 'Mike Lively')
219 PHPUnit_Extensions_Database_TestCase::assertTablesEqual($table, $actual);
222 public function testGetRow()
224 $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementTable(
225 $this->startingTable,
226 array('[NULL]' => NULL),
227 array('%%%name%%%' => 'Mike Lively')
233 'column1' => 'My name is Mike Lively',
236 'column4' => 'yghkf;a hahfg8ja h;'
244 'column1' => 'ha;gyt',
246 'column3' => '[NULL] not really',
253 public function testGetValue()
255 $actual = new PHPUnit_Extensions_Database_DataSet_ReplacementTable(
256 $this->startingTable,
257 array('[NULL]' => NULL),
258 array('%%%name%%%' => 'Mike Lively')
261 $this->assertNull($actual->getValue(2, 'column4'));
262 $this->assertEquals('My name is Mike Lively', $actual->getValue(0, 'column1'));